package com.learn.jdk.caseDemo;

import org.junit.Test;

import java.util.Optional;

/**
 * Copyright: Copyright (c) 2020 Asiainfo
 *
 * @ClassName: com.learn.jdk.caseDemo.OptionalDemo
 * @Description: 该类的功能描述
 * @version: v1.0.0
 * @author: lipan
 * @date: 2020/5/20 17:57
 * <p>
 * Modification History:
 * Date         Author          Version            Description
 * ------------------------------------------------------------
 * 2020/5/20      lipan          v1.0.0               修改原因
 */

public class OptionalDemo {


     @Test
    public void test() throws Exception{


        User u=new User(1,"aa");
        u=null;
        Integer pp = Optional.ofNullable(u).map(u1 -> {
            System.out.println("pp");
            return u1.getId();
        }).orElse(1);

         System.out.println(pp);
    }





    class User{


        public User(int id, String name) {
            this.id = id;
            this.name = name;
        }

        private int id;

       private   String name;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }


}
